<template>

	<view class="content">
			<view>
				<navigator url="/pages/index/bbs/addarticle"><button type="default" size="mini">发布文章</button></navigator>
				<navigator url="/pages/index/bbs/attention"><button type="default" size="mini">查看我的关注</button></navigator>
				<navigator url="/pages/index/bbs/userartice"><button type="default" size="mini">查看我发布的文章</button></navigator>
			</view>
		<view class="page-section" indexListBox>
			<view class="indexList" v-for="(item,index) in tableData" :key="index">
	
					<view>作者:{{item.fileAuthor}} &nbsp;</view>
					<view>标题:{{item.fileTitle}} &nbsp;</view>
					<view>内容:{{item.fileContents}} &nbsp;</view>
					<!-- 图片回显有问题 -->
				   <view>
					 <image :src="item.fileFile" style="width: 200rpx;height: 100rpx;"></image>
					</view>
					
					<view>
						<!-- <button class="mini-btn" type="warn" size="mini" form-type="submit"  @click="bbslive(item.fileId)">点赞</button> -->
	                     <template  v-bind:id="item.fileId">
	                            <button @click="bbslive(item)"  size="mini" type="warn" >点赞</button>
	                         </template>
						<view>点赞量:{{item.bbsLive}}</view>
						<template  v-bind:id="item.authorId">
						       <button @click="attention(item)"  size="mini" type="warn" >关注</button>
						    </template>
					</view>
					
					<!-- 评论 -->
			   <template  v-bind:id="item.fileId">
							<input class="uni-input" confirm-type="search" v-model="commentContent" placeholder="请编写您的评论" />
							<button size="mini" type="primary" @click="addComments(item)" plain>提交</button>
						</template>
						<!-- 所有评论 -->
				<view>
					<!-- <button class="mini-btn" type="warn" size="mini" form-type="submit"  @click="bbslive(item.fileId)">点赞</button> -->
				     <template  v-bind:id="item.fileId">
				            <button @click="findcommentArticle(item)"  size="mini" type="warn" >查看评论</button>
				         </template>
						 <view class="indexList" v-for="(item,index) in comments" :key="index">
							 <view>评论:{{item}}</view>
						 </view>
					
			
				</view>
		</view>
	</view>
</view>	
</template>

<script>
	export default {
		data() {
			return {
				fileId:'',
				tableData: [],
				commentContent :'',
				comments:[]
			}
		},onLoad(){
			this.tasklist();

		},
		methods:{
			tasklist(){
				uni.request({
				    url: 'http://localhost:7000/bbs/bbs/findall', //仅为示例，并非真实接口地址。
				    method: 'POST',
				    success: (res) => {
						console.log(res.data.data)
				        this.tableData=res.data.data
						//console.log(this.Data)
				    }
				});
			},
		
		   goto(url) {
				uni.navigateTo({
					url:"/pages/index/bbs/addarticle"
				})
			},
			bbslive(item){
				console.log("------------------------------",item)
				this.fileId=item.fileId
			   uni.request({
			       url: 'http://localhost:7000/bbs/bbs/insertbbslive',//仅为示例，并非真实接口地址。
				data: {
					userId:2,
					fileId:this.fileId,
					authorId:this.authorId
				},
			       method: 'POST',
			       success: (res) => {
			   		console.log(res.data.data)
			           this.tableData=res.data.data
			   		console.log(this.Data)
						this.tasklist()
			       }
			   });
			   console.log(this.fileId)
			},
			attention(item){
				console.log("------------------------------",item)
				this.authorId=item.userId
				uni.request({
				url: 'http://localhost:7000/bbs/bbs/insertbbsattention',//仅为示例，并非真实接口地址。
				data: {
						userId:3,
						authorId:this.authorId
					},
				       method: 'POST',
				       success: (res) => {
				   		console.log(res.data.data)
				           this.tableData=res.data.data
				   		console.log(this.Data)
						this.tasklist()
				       }
				   });
				   console.log(this.fileId)
				},	
				addComments(itme){
					this.fileId=itme.fileId,
					console.log("文章id"+this.fileId)
								uni.request({
								    url: `http://localhost:7000/bbs/bbs/insertbbscomment/`, //接口地址。
									data:{
										fileId: this.fileId,
										userId: 999,
										commentContent: this.commentContent,
									},
									method:'POST',
								    success: (res) => {
										this.commentContent = '' 
										// Location.reload()
										uni.showToast({
											title: res.data.msg,
											duration: 2000
										});
								        console.log(res.data);
								    }
								});
						},
				findcommentArticle(item){
					this.fileId=item.fileId;
					uni.request({
					    url: 'http://localhost:7000/bbs/bbs/findcomment',//仅为示例，并非真实接口地址。
						data: {
							fileId:this.fileId
						},
					    method: 'POST',
					    success: (res) => {
							console.log(res.data.data)
					        this.comments=res.data.data
							//console.log(this.Data)
					    }
					});
				},
		},
		
	}
</script>

 <style>
	 .indexList uni-image {
	            width: 100%;
	            height: 130px;
	            background: #eaeaea;
	        }
	        .indexList {
	            margin-top: 15px;
	            margin-bottom: 15px;
	        }
	        .indexList .title {
	            background: #000;
	            color: #fff;
	            font-size: 16px;
	            line-height: 37px;
	            padding: 0 10px;
	            margin-top: -5px;
	    }
	       .indexListBox{
	           margin-top: 20px;
	       }
		   .image {
		   		width: 50rpx;
		   		height: 80rpx;
		   	}

</style>

 
